﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;

namespace T.FAS.Runtime.DataAccess.SPI
{
    /// <summary>
    /// 关联关系中的关联项集合类
    /// </summary>
    [Serializable]
    public class AssociateItemCollection : Collection<AssociateItem>, ICloneable
    {
        #region 常量

        #endregion

        #region 字段

        #endregion

        #region 构造函数       

        /// <summary>
        /// 隐式转换构造函数
        /// </summary>
        /// <param name="items">关联关系中的关联项数组</param>
        /// <returns>关联关系中的关联项集合</returns>
        public static implicit operator AssociateItemCollection(AssociateItem[] items)
        {
            var collection = new AssociateItemCollection();
            collection.AddRange(items);

            return collection;
        }

        #endregion

        #region 属性

        #endregion

        #region 方法      

        /// <summary>
        /// 添加关联项
        /// </summary>
        /// <param name="item">关联项</param>
        public void Add(AssociateItem item)
        {
            base.Add(item);
        }

        /// <summary>
        /// 批量添加关联项
        /// </summary>
        /// <param name="items">关联项集合</param>
        public void AddRange(AssociateItem[] items)
        {
            foreach (AssociateItem item in items)
                Add(item);
        }

        /// <summary>
        /// 克隆
        /// </summary>
        /// <returns>对象关联项集合的副本</returns>
        public object Clone()
        {
            var newCollection = new AssociateItemCollection();

            foreach (var item in this.Items)
            {
                newCollection.Add(item);
            }

            return newCollection;
        }

        #endregion
    }
}
